package com.qdlc.p2p.manage.action;
/*package com.rd.p2p.manage.action.tpp;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.opensymphony.xwork2.ModelDriven;
import com.rd.p2p.common.model.jpa.PageDataList;
import com.rd.p2p.common.util.NumberUtil;
import com.rd.p2p.common.util.StringUtil;
import com.rd.p2p.core.account.service.AccountRechargeService;
import com.rd.p2p.core.core.Global;
import com.rd.p2p.core.core.constant.Constant;
import com.rd.p2p.core.core.util.OrderNoUtils;
import com.rd.p2p.core.core.web.BaseAction;
import com.rd.p2p.core.tpp.chinapnr.model.ChinapnrAccts;
import com.rd.p2p.core.tpp.chinapnr.model.ChinapnrHelper;
import com.rd.p2p.core.tpp.chinapnr.model.ChinapnrModel;
import com.rd.p2p.core.tpp.domain.TppMerchantLog;
import com.rd.p2p.core.tpp.model.TppMerchantLogModel;
import com.rd.p2p.core.tpp.model.TppModel;
import com.rd.p2p.core.tpp.service.TppMerchantLogService;
import com.rd.p2p.core.tpp.tppInterface.TppBaseInterface;
import com.rd.p2p.core.user.domain.User;
import com.rd.p2p.core.user.service.UserService;

*//**
 * 汇付天下第三方商户平台操作
 * （因为转账、取现等接口仅汇付天下存在，故汇付天下平台操作单独处理）
 * 
 *
 * @author ylx
 * @version 2.0
 * @date 2015年6月19日 上午9:28:36
 *//*
public class ManageTppChinapnrMerchantLogAction extends BaseAction<TppMerchantLogModel> implements ModelDriven<TppMerchantLogModel> {
	
	private static Logger logger = Logger.getLogger(ManageTppChinapnrMerchantLogAction.class);
	
	@Resource
	private TppMerchantLogService tppMerchantLogService;
	@Resource
	private UserService userService;
	@Resource
	private AccountRechargeService accountRechargeService;
	
	private Map<String, Object> data;
	
	*//**
	 * 第三方商户平台操作管理界面
	 * 
	 * @return
	 * @throws Exception
	 *//*
	@Action("/modules/tpp/tppMerchantLog/" + Constant.TPP_PACKAGE + "/tppMerchantLogManager")
	public String tppMerchantLogManager() throws Exception {
		
		return "tppMerchantLogManager";
	}
	
	*//**
	 * 第三方商户平台操作记录
	 * 
	 * @throws Exception
	 *//*
	@Action("/modules/tpp/tppMerchantLog/" + Constant.TPP_PACKAGE + "/tppMerchantLogList")
	public void tppMerchantLogList() throws Exception {
		String status = paramString("status");
		if (StringUtil.isBlank(status)) {
			model.setStatus((byte) 99);
		}
		String type = paramString("type");
		if (StringUtil.isBlank(type)) {
			model.setType((byte) 99);
		}
		PageDataList<TppMerchantLogModel> pageList = tppMerchantLogService.list(model);
		int totalPage = pageList.getPage().getTotal();
		data = new HashMap<String, Object>();
		data.put("total", totalPage);
		data.put("rows", pageList.getList());
		printJson(getStringOfJpaObj(data));
	}
	
	*//**
	 * 第三方商户充值页面
	 * 
	 * @return
	 * @throws Exception
	 *//*
	@Action("/modules/tpp/tppMerchantLog/" + Constant.TPP_PACKAGE + "/tppMerchantRechargePage")
	public String tppMerchantRechargePage() throws Exception {
		
		return "tppMerchantRechargePage";
	}
	
	*//**
	 * 第三方商户充值
	 * 
	 * @return
	 * @throws Exception
	 *//*
	@Action(value = "/modules/tpp/tppMerchantLog/" + Constant.TPP_PACKAGE + "/tppMerchantRecharge", 
			results = { @Result(name = "result", type = "ftl", location = "modules/tpp/tppMerchantLog/" + Constant.TPP_PACKAGE + "/recharge.html")})
	public String tppMerchantRecharge() throws Exception {
		logger.info("商户充值...");
		model.validMoney();
		
		// 封装第三方处理参数
    	TppModel tppModel = new TppModel();
    	tppModel.setMoney(model.getMoney());
		TppBaseInterface tppService =(TppBaseInterface)tppModel.tppServiceFactory();
		Object rechargeObj = tppService.tppMerchantRecharge(tppModel);
		
		// 保存平台操作记录
		TppMerchantLog merchantLog = new TppMerchantLog(getOperator(), null, null, model.getMoney(), 0,
				TppMerchantLogModel.STATUS_UNTREATED, TppMerchantLogModel.TYPE_MERCHANT_RECHARGE, tppModel.getOrderId(), "待处理");
		tppMerchantLogService.save(merchantLog);
		request.setAttribute("recharge", rechargeObj);
		return "result";
	}
	
	*//**
	 * 第三方商户平台账户间转账页面
	 * 
	 * @return
	 * @throws Exception
	 *//*
	@Action("/modules/tpp/tppMerchantLog/" + Constant.TPP_PACKAGE + "/tppMerchantTransferPage")
	public String tppMerchantTransferPage() throws Exception {
		// 获取商户子账户信息
		String resp = ChinapnrHelper.queryAcctschin().submit();
		
		// 截取商户子账户信息Json字符串
		String jsonStr = resp.substring(resp.indexOf("["), resp.lastIndexOf("]") + 1);
		
		List<ChinapnrAccts> accts = new ArrayList<ChinapnrAccts>();
		
		// 解析Json字符串并封装子账户信息对象
		JSONArray array = JSON.parseArray(jsonStr);
		if (array != null) {
			for (int i = 0; i < array.size(); i++) {
				JSONObject object = array.getJSONObject(i);
				ChinapnrAccts chinapnrAccts = new ChinapnrAccts();
				chinapnrAccts.setAcctBal(object.getDouble("AcctBal"));
				chinapnrAccts.setAcctType(object.getString("AcctType"));
				chinapnrAccts.setAvlBal(object.getDouble("AvlBal"));
				chinapnrAccts.setFrzBal(object.getDouble("FrzBal"));
				chinapnrAccts.setSubAcctId(object.getString("SubAcctId"));
				accts.add(chinapnrAccts);
			}
		}
		request.setAttribute("accts", accts);
		return "tppMerchantTransferPage";
	}
	
	*//**
	 * 第三方商户平台间转账
	 * 
	 * @throws Exception
	 *//*
	@Action("/modules/tpp/tppMerchantLog/" + Constant.TPP_PACKAGE + "/tppMerchantTransfer")
	public void tppMerchantTransfer() throws Exception {
		// 校验数据
		model.validTransfer();
		String ordId = OrderNoUtils.getSerialNumber();
		
		String msg = "操作成功";
		byte status = TppMerchantLogModel.STATUS_SUCEESS;
		// 执行转账业务
		ChinapnrModel retModel = ChinapnrHelper.transfer(NumberUtil.format2Str(model.getMoney()), Global.getValue("tpp_merid"), ordId, 
				model.getToAccount(), model.getAccount());
		if (retModel == null || !retModel.success()) {
			status = TppMerchantLogModel.STATUS_FAIL;
			msg = retModel.getRespDesc();
		}
		// 保存平台操作记录
		TppMerchantLog merchantLog = new TppMerchantLog(getOperator(), model.getAccount(), model.getToAccount(), model.getMoney(), 0,
				status, TppMerchantLogModel.TYPE_MERCHANT_TRANSFER, ordId, msg);
		tppMerchantLogService.save(merchantLog);
		printWebSuccess();
	}
	
	*//**
	 * 第三方商户平台提现页面
	 * 
	 * @return
	 * @throws Exception
	 *//*
	@Action("/modules/tpp/tppMerchantLog/" + Constant.TPP_PACKAGE + "/tppMerchantCashPage")
	public String tppMerchantCashPage() throws Exception {
		
		return "tppMerchantCashPage";
	}
	
	*//**
	 * 第三方商户平台提现
	 * 
	 * @return
	 * @throws Exception
	 *//*
	@Action(value = "/modules/tpp/tppMerchantLog/" + Constant.TPP_PACKAGE + "/tppMerchantCash",
			results = { @Result(name = "result", type = "ftl", location = "modules/tpp/tppMerchantLog/" + Constant.TPP_PACKAGE + "/cash.html")})
	public String tppMerchantCash() throws Exception {
		logger.info("商户充值...");
		model.validMoney();
		// 封装第三方处理参数
    	TppModel tppModel = new TppModel();
    	tppModel.setMoney(model.getMoney());
		TppBaseInterface tppService =(TppBaseInterface)tppModel.tppServiceFactory();
		Object cashObj = tppService.tppMerchantCash(tppModel);
		
		// 保存平台操作记录
		TppMerchantLog merchantLog = new TppMerchantLog(getOperator(), null, null, model.getMoney(), 0,
				TppMerchantLogModel.STATUS_UNTREATED, TppMerchantLogModel.TYPE_MERCHANT_CASH, tppModel.getOrderId(), "待处理");
		tppMerchantLogService.save(merchantLog);
		
		request.setAttribute("cash", cashObj);
		return "result";
	}
	
	*//**
	 * 第三方商户给用户转账页面
	 * 
	 * @return
	 * @throws Exception
	 *//*
	@Action("/modules/tpp/tppMerchantLog/" + Constant.TPP_PACKAGE + "/tppTransferPage")
	public String tppTransferPage() throws Exception {
		// 获取商户子账户信息
		String resp = ChinapnrHelper.queryAcctschin().submit();
		
		// 截取商户子账户信息Json字符串
		String jsonStr = resp.substring(resp.indexOf("["), resp.lastIndexOf("]") + 1);
		
		List<ChinapnrAccts> accts = new ArrayList<ChinapnrAccts>();
		
		// 解析Json字符串并封装子账户信息对象
		JSONArray array = JSON.parseArray(jsonStr);
		if (array != null) {
			for (int i = 0; i < array.size(); i++) {
				JSONObject object = array.getJSONObject(i);
				ChinapnrAccts chinapnrAccts = new ChinapnrAccts();
				chinapnrAccts.setAcctBal(object.getDouble("AcctBal"));
				chinapnrAccts.setAcctType(object.getString("AcctType"));
				chinapnrAccts.setAvlBal(object.getDouble("AvlBal"));
				chinapnrAccts.setFrzBal(object.getDouble("FrzBal"));
				chinapnrAccts.setSubAcctId(object.getString("SubAcctId"));
				accts.add(chinapnrAccts);
			}
		}
		request.setAttribute("accts", accts);
		return "tppTransferPage";
	}
	
	*//**
	 * 第三方商户给用户转账
	 * 
	 * @throws Exception
	 *//*
	@Action("/modules/tpp/tppMerchantLog/" + Constant.TPP_PACKAGE + "/tppTransfer")
	public void tppTransfer() throws Exception {
		User user = userService.getUserByUserName(paramString("userName"));
		model.validUser(user);
		model.setToAccount(user.getUserName());
		model.validTransfer();
		
		String ordId = OrderNoUtils.getSerialNumber();
		
		String msg = "操作成功";
		byte status = TppMerchantLogModel.STATUS_SUCEESS;
		// 执行转账业务
		ChinapnrModel retModel = ChinapnrHelper.transfer(NumberUtil.format2Str(model.getMoney()), user.getTppUserCustId(), ordId, "", model.getAccount());
		if (retModel == null || !retModel.success()) {
			status = TppMerchantLogModel.STATUS_FAIL;
			msg = retModel.getRespDesc();
		} else {
			// 保存用户充值记录
			accountRechargeService.systemRecharge(ordId, NumberUtil.getDouble(retModel.getTransAmt()), user, getOperator());
		}
		// 保存平台操作记录
		TppMerchantLog merchantLog = new TppMerchantLog(getOperator(), model.getAccount(), user.getUserName(), model.getMoney(), 0,
				status, TppMerchantLogModel.TYPE_TRANSFER, ordId, msg);
		tppMerchantLogService.save(merchantLog);
		printWebSuccess();
	}
}
*/